﻿using Microsoft.AspNetCore.Mvc.Filters;

namespace ERP.API
{
    /// <summary>
    /// 全局异常过滤器
    /// </summary>
    public class CustomException:IExceptionFilter
    {
        /// <summary>
        /// 日志
        /// </summary>
        private readonly ILogger<CustomException> logger;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="logger">日志</param>

        public CustomException(ILogger<CustomException> logger)
        {
            this.logger = logger;
        }

        /// <summary>
        /// 当异常发生时
        /// </summary>
        /// <param name="context"></param>
        public void OnException(ExceptionContext context)
        {
            logger.LogError("【全局异常过滤器】"+context.Exception.Message);
        }
    }
}
